import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class DodajUzytkownika extends JFrame{
	
	JLabel l1 = new JLabel("Podaj numer:   ", SwingConstants.RIGHT);
	JLabel l2 = new JLabel("Podaj imię:   ", SwingConstants.RIGHT);
	JLabel l3 = new JLabel("Podaj nazwisko:   ", SwingConstants.RIGHT);
	JLabel l4 = new JLabel("Podaj login:   ", SwingConstants.RIGHT);
	JLabel l5 = new JLabel("Podaj hasło:   ", SwingConstants.RIGHT);
	JLabel l6 = new JLabel("Powtórz hasło:   ", SwingConstants.RIGHT);
	
	JTextField t1 = new JTextField();
	JTextField t2 = new JTextField();
	JTextField t3 = new JTextField();
	JTextField t4 = new JTextField();
	JPasswordField t5 = new JPasswordField();
	JPasswordField t6 = new JPasswordField();
	
	JButton dodaj = new JButton("Dodaj");
	JButton powrót = new JButton("Anuluj");
	
	JPanel p1 = new JPanel();
	JPanel p2 = new JPanel();
	JPanel p3 = new JPanel();
	JPanel p4 = new JPanel();
	JPanel p5 = new JPanel();
	JPanel p6 = new JPanel();
	JPanel p7 = new JPanel();
	
	public DodajUzytkownika(){
		super("Dodaj użytkownika");
		
		setLayout(new GridLayout(7,1));
		add(p1);
		add(p2);
		add(p3);
		add(p4);
		add(p5);
		add(p6);
		add(p7);
		
		p1.setLayout(new GridLayout(1,2));
		p1.add(l1);
		p1.add(t1);
		p2.setLayout(new GridLayout(1,2));
		p2.add(l2);
		p2.add(t2);
		p3.setLayout(new GridLayout(1,2));
		p3.add(l3);
		p3.add(t3);
		p4.setLayout(new GridLayout(1,2));
		p4.add(l4);
		p4.add(t4);
		p5.setLayout(new GridLayout(1,2));
		p5.add(l5);
		p5.add(t5);
		p6.setLayout(new GridLayout(1,2));
		p6.add(l6);
		p6.add(t6);
		p7.setLayout(new FlowLayout());
		p7.add(dodaj);
		p7.add(powrót);
		
		
		setSize(500,300);
		setLocation(400, 250);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
		
		powrót.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
			new OknoBibliotekaAdmin();	
			dispose();
            }
		});
		
		dodaj.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
            String password1 = new String(t5.getPassword());
            String password2 = new String(t6.getPassword());
            
            	if(password1.equals(password2))
            	{
            		JOptionPane.showMessageDialog(null, "Rejestracja zakończona pomyślnie!");
            		dispose();
            	}
            	else
            	{
            		JOptionPane.showMessageDialog(null, "Podane hasła nie są identyczne!");
            	}
            	}

           });
		}
	
	public static void main(String[] args){
		new DodajUzytkownika();
	}
}
